package fr.vvins.core.dao;

public abstract class EntityImpl implements Entity {
	
	@Override
	public String getEntityName(){
		return this.getClass().getSimpleName();
	}
	@Override
	public String toString(){
		return "["  + getEntityName() + ":" + getId() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((getEntityName() == null) ? 0 : getEntityName().hashCode());
		if(getId() != null){
		result = prime * result + getId();
		} else {
			result = prime * result + 1000;
		}
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EntityImpl other = (EntityImpl) obj;
		if (getEntityName() == null) {
			if (other.getEntityName() != null)
				return false;
		} else if (!getEntityName().equals(other.getEntityName()))
			return false;
		if (getId() != other.getId())
			return false;
		return true;
	}
	
}
